package com.kfm.base.thread.day01;

import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;

public class Exer01 {

    public static void main(String[] args) {
        Thread t1 = new Thread( () -> {
            for (int i = 1; i <= 10; i++) {
                if (i % 2 != 0){
                    System.out.println(Thread.currentThread().getName() + " : " + i);
                }
            }
        }, "奇数");

        Thread t2 = new Thread(() -> {
            for (int i = 1; i < 11; i++) {
                if (i % 2 ==0){
                    System.out.println(Thread.currentThread().getName() + " : " + i);
                }
            }
        }, "偶数");

        t1.start();
        t2.start();

        FutureTask<Integer> sumFuture = new FutureTask<>(() -> {
            int sum = 0;
            for (int i = 1; i <= 10; i++) {
                sum += i;
            }
            return sum;
        });

        Thread thread = new Thread(sumFuture);

        thread.start();

        try {
            // 等待线程执行完毕并返回结果
            System.out.println(sumFuture.get());
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        } catch (ExecutionException e) {
            throw new RuntimeException(e);
        }


        Thread t3 = new Thread(){
          @Override
          public void run(){

          }
        };


    }
}

class A extends Thread{
    @Override
    public void run(){

    }
}
